"use strict";
const common_vendor = require("../../common/vendor.js");
const common_api = require("../../common/api.js");
const common_const = require("../../common/const.js");
const common_url = require("../../common/url.js");
require("../../common/request.js");
const _sfc_main = {
  data() {
    return {
      backgroundURL: common_const.urlPrefix + "/img/login/background.png",
      titleText: "心灵绿野",
      infoTexts: ["随心倾述", "自在畅聊"],
      wxLoginText: "微信登录",
      wxLoginIcon: common_url.Icons.WxLogin,
      agreeText: ["我同意", "和"],
      userServiceText: "《用户服务协议》",
      privacyText: "《隐私条款》",
      agreeRedio: false,
      url: "https://heart-field-1312908194.cos.ap-shanghai.myqcloud.com",
      code: "",
      userInfo: {}
    };
  },
  methods: {
    gotoAgreementPage(type) {
      common_vendor.index.navigateTo({
        url: "/pages/agreement/agreement?type=" + type
      });
    },
    doLogin() {
      if (this.agreeRedio) {
        common_vendor.index.getUserProfile({
          desc: "用户信息展示",
          success: (info) => {
            common_vendor.index.showLoading();
            console.log(info);
            console.log(this.code);
            common_api.login({
              "code": this.code,
              "encryptedData": info.encryptedData,
              "iv": info.iv
            }).then((res) => {
              common_vendor.index.hideLoading();
              console.log(res.data);
              common_vendor.index.setStorage({
                key: "user",
                data: {
                  "token": res.data.accessToken,
                  "id": res.data.userId,
                  "info": res.data.userInfo
                }
              }).then(() => {
                common_vendor.index.reLaunch({ url: "/pages/index/index" });
                common_vendor.index.showToast({
                  icon: "none",
                  title: "登录成功"
                });
              });
            });
          },
          fail: (err) => {
            common_vendor.index.showToast({ title: "微信登录授权失败，授权后访问小程序！", icon: "none" });
          }
        });
        common_vendor.index.get;
      } else {
        common_vendor.index.showToast({ title: "请勾选同意协议后再登录", icon: "none" });
      }
    }
  },
  onLoad() {
    common_vendor.index.login({
      provider: "weixin",
      success: (loginRes) => {
        this.code = loginRes.code;
      }
    });
  }
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  return {
    a: common_vendor.t($data.titleText),
    b: common_vendor.t($data.infoTexts[0]),
    c: common_vendor.t($data.infoTexts[1]),
    d: common_vendor.t($data.wxLoginIcon),
    e: common_vendor.t($data.wxLoginText),
    f: common_vendor.o((...args) => $options.doLogin && $options.doLogin(...args)),
    g: $data.agreeRedio,
    h: common_vendor.o(($event) => $data.agreeRedio = true),
    i: common_vendor.t($data.agreeText[0]),
    j: common_vendor.t($data.userServiceText),
    k: common_vendor.o(($event) => $options.gotoAgreementPage("user")),
    l: common_vendor.t($data.agreeText[1]),
    m: common_vendor.t($data.privacyText),
    n: common_vendor.o(($event) => $options.gotoAgreementPage("privacy")),
    o: "url(" + $data.backgroundURL + ")"
  };
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "D:/Project/heart-3.0/heart-field-3.0/pages/login/login.vue"]]);
wx.createPage(MiniProgramPage);
